home *** CD-ROM | disk | FTP | other *** search
/ ARRL Handbook 2008 12.0 / arrl_handbook_2008_cd.bin / program files / ARRL 2008 Handbook / Software / DOS Software / Chap 5 - a2d / A2D.BAS next >
Encoding:
BASIC Source File  |  2002-04-24  |  5.0 KB  |  105 lines

  1. 10 REM N1ii May 9, 1995 V1.0
  2. 15 '2 CHANNEL VOLT METER VERSION
  3. 20 REM This software makes 2 A/D conversions and
  4. 30 REM reads them out serially into a parallel
  5. 40 REM printer port on a PC
  6. 50 REM ***********************
  7. 60 REM initial setup
  8. 70 SCREEN 0                     'pick 80 column text mode
  9. 80 COLOR 2, 0                   'I like green on black
  10. 90 CLS                          'First clear the screen
  11. 100 CLEAR                       'Then clear all variables
  12. 105 PORTO = &H378              'Define output port
  13. 110 DEFINT A-O                  'all varib. starting w/ A-O are integers
  14. 120 TFIX0 = 4.9 / 255           'scale factor for channel 0
  15. 130 TFIX1 = 4.9 / 255           'scale factor for channel 1
  16. 135 NOMORE$ = ""                'set varible to blank
  17. 200 '*************************   This is the start of the program
  18. 210 WHILE NOMORE$ = ""
  19. 220 NOMORE$ = INKEY$            'Push any key to quit
  20. 230 OUT PORTO,10               'Data bit 3, Pin 5 (CS) goes high
  21. 240                             'and data bit 1, pin 3 (DI) goes high
  22. 250 OUT PORTO,2                'CS goes low and DI stays high
  23. 260 GOSUB 1000                  'first clock pulse
  24. 270                             'DI stays high for single ended conversion
  25. 280 GOSUB 1000                  'second clock pulse
  26. 290 OUT PORTO,0                'now select input channel 0 - DI low
  27. 300 GOSUB 1000                  'third clock pulse
  28. 310                             'now the data read-in starts
  29. 320 FOR CLK = 7 TO 0 STEP -1    'going to generate 8 clocks
  30. 330 GOSUB 1000
  31. 340 INBIT = INP(PORTO+1)        'going to look at pin 10 (2^7+2^6+...)
  32. 350                             '  after each clock
  33. 360 IF INBIT < 125 THEN INVAL = 1 ELSE INVAL = 0'if (not ack) is low then
  34. 370                             '                  the input bit is a one
  35. 380 TOTAL0 = TOTAL0 + INVAL * (2 ^ CLK)'form decimal number from INBITs
  36. 390 NEXT CLK                    'next clk to get next inbit
  37. 400 TOTAL0 = TFIX0 * TOTAL0     'fix calibration Channel 0
  38. 410 FOR CLK = 0 TO 7 STEP 1     '8 more clocks needed
  39. 420 GOSUB 1000
  40. 430 NEXT CLK
  41. 440 GOSUB 1000                  'couple more clocks with CS low
  42. 450 GOSUB 1000
  43. 460 OUT PORTO,10               'CS goes high (conversions over)
  44. 470 GOSUB 1000                  'couple more clocks with CS high
  45. 480 GOSUB 1000                  ' clears internal registers
  46. 500 REM NOW RUN THE PROGRAM AGAIN FOR CHANNEL 1
  47. 510 OUT PORTO,10              'Data bit 3, Pin 5 (CS) goes high
  48. 520                             'and data bit 1, pin 3 (DI) goes high
  49. 530 OUT PORTO,2                'CS goes low and DI stays high
  50. 540 GOSUB 1000                  'first clock pulse
  51. 550                             'DI stays high for single ended conversion
  52. 560 GOSUB 1000                  'second clock pulse
  53. 570 OUT PORTO,2                'now select input channel 1 - DI HIGH
  54. 580 GOSUB 1000                  'third clock pulse
  55. 590                             'now the data read-in starts
  56. 600 FOR CLK = 7 TO 0 STEP -1    'going to generate 8 clocks
  57. 610 GOSUB 1000
  58. 620 INBIT = INP(PORTO+1)        'going to look at pin 10 (2^7+2^6+...)
  59. 630                             '  after each clock
  60. 640 IF INBIT < 125 THEN INVAL = 1 ELSE INVAL = 0'if (not ack) is low then
  61. 650                             '                  the input bit is a one
  62. 660 TOTAL1 = TOTAL1 + INVAL * (2 ^ CLK)'form decimal number from INBITs
  63. 670 NEXT CLK                    'next clk to get next inbit
  64. 680 TOTAL1 = TFIX1 * TOTAL1     'fix calibration Channel 1
  65. 690 FOR CLK = 0 TO 7 STEP 1     '8 more clocks needed
  66. 700 GOSUB 1000
  67. 710 NEXT CLK
  68. 720 GOSUB 1000                  'couple more clocks with CS low
  69. 730 GOSUB 1000
  70. 740 OUT PORTO,10               'CS goes high (conversions over)
  71. 750 GOSUB 1000                  'couple more clocks with CS high
  72. 760 GOSUB 1000                  ' clears internal registers
  73. 780 GOSUB 2000                  'now process the output for display
  74. 790 WEND
  75. 800 END
  76. 1000  'clock subroutine
  77. 1010 CD = 1                    'set clock width
  78. 1020 OUT (PORTO+2),0            'set pin 14 (autolf (not)) high
  79. 1030                           ' this sets clock high
  80. 1040 FOR CW = 0 TO CD STEP 1: NEXT CW 'set clock pulse width
  81. 1050 OUT (PORTO+2),2            'set pin 14 low (end of clock pulse)
  82. 1060 RETURN
  83. 2000 REM subroutine for displaying the results
  84. 2010 REM This space used for processing TOTAL0 and TOTAL1
  85. 2020 REM       the outputs of the two measurment channels
  86. 2030 LOCATE 1, 1                 'the next few steps prints the
  87. 2040 PRINT "Channel 0 ="         'outputs of channel 0 and 1
  88. 2050 LOCATE 2, 4
  89. 2060 PRINT USING "##.##"; TOTAL0
  90. 2070 LOCATE 1, 30
  91. 2080 PRINT "Channel 1= "
  92. 2090 LOCATE 2, 34
  93. 2100 PRINT USING "##.##"; TOTAL1
  94. 2110 LOCATE 5, 1
  95. 2120 TDELTA = ABS(TOTAL0 - TOTAL1)
  96. 2130 IF TDELTA < .001 THEN GOTO 2190
  97. 2140 PRINT "SWR = "
  98. 2150 SWR = ABS((TOTAL0 + TOTAL1) / (TOTAL0 - TOTAL1))
  99. 2160 LOCATE 6, 4
  100. 2170 PRINT USING "###########.##"; SWR
  101. 2180 RETURN
  102. 2190 LOCATE 6, 4
  103. 2200 PRINT "SWR NOT VALID!"
  104. 2210 RETURN
  105.